package com.wits.qso.entity;

import java.util.Date;
import java.util.List;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.util.PropertyFilter;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;

import com.wits.platform.common.JsonDateValueProcessor;
import com.wits.platform.entity.BaseEntity;

/**
 * 
 * @see 讨论组
 *
 */
@Entity
@Table(name="qso_discussion_group")
public class DiscussionGroup extends BaseEntity{

	
	/**
	 * 
	 */
	private static final long serialVersionUID = -3963297311706853557L;

	private String id;
	
	/** 讨论主题 **/
	private String topic;
	
	/** 讲解老师 Id **/
	private String teaId;
	
	/** 讲解老师 姓名 **/
	private String teaName;
	
	/** 连接被指导虚机的学生(对应的userId) **/
	private String vmUserId;
	
	private String vmUserName;
	
	private String status;

	/**  讨论组解决的 问题id串**/
	private String helpIds;


	private List<DiscussItems> items;
	
	
	private Set<DiscussionMember> members;


	@Id
	@GenericGenerator(name = "idGen", 
					strategy = "com.wits.platform.common.id.generator.IDGenerator",
					parameters={ 
								@Parameter(name = "segment_value", value = "QSO_DISCUSSION_GROUP_ID"), 
								@Parameter(name="table_name",value="wits_id_generator"),
								@Parameter(name="value_column_name",value="gen_value"),
								@Parameter(name="segment_column_name",value="gen_name"),
								@Parameter(name="segment_value_length",value="36"),
								@Parameter(name="sq_format",value=""), 
								@Parameter(name="sq_prefix",value="") 
					})
	@GeneratedValue(generator = "idGen")
	@Column(name = "id", nullable = false, insertable = true, updatable = false, length = 36)
	public String getId() {
		return id;
	}


	public void setId(String id) {
		this.id = id;
	}


	@Column(name="topic",length=100)
	public String getTopic() {
		return topic;
	}


	public void setTopic(String topic) {
		this.topic = topic;
	}

	@Column(name="tea_id",length=36)
	public String getTeaId() {
		return teaId;
	}


	public void setTeaId(String teaId) {
		this.teaId = teaId;
	}

	@Column(name="tea_name",length=50)
	public String getTeaName() {
		return teaName;
	}

	public void setTeaName(String teaName) {
		this.teaName = teaName;
	}

	@Column(name="vm_user_id",length=36)
	public String getVmUserId() {
		return vmUserId;
	}


	public void setVmUserId(String vmUserId) {
		this.vmUserId = vmUserId;
	}
	
	@Column(name="vm_user_name",length=50)
	public String getVmUserName() {
		return vmUserName;
	}


	public void setVmUserName(String vmUserName) {
		this.vmUserName = vmUserName;
	}

	@Column(name="status",length=2)
	public String getStatus() {
		return status;
	}


	public void setStatus(String status) {
		this.status = status;
	}

	@Column(name="help_ids",length=400)
	public String getHelpIds() {
		return helpIds;
	}

	public void setHelpIds(String helpIds) {
		this.helpIds = helpIds;
	}
	
	@OneToMany
	@JoinColumn(name="group_id",insertable=true)
	public List<DiscussItems> getItems() {
		return items;
	}


	public void setItems(List<DiscussItems> items) {
		this.items = items;
	}

	@OneToMany(fetch=FetchType.LAZY,mappedBy="id.groupId")
	public Set<DiscussionMember> getMembers() {
		return members;
	}


	public void setMembers(Set<DiscussionMember> members) {
		this.members = members;
	}

	@Override
	public String display() {
		// TODO Auto-generated method stub
		return null;
	}


	private static JsonConfig jsonConfig = new JsonConfig();

	@Transient
	protected JsonConfig getJsonConfig() {
		return jsonConfig;
	}

	static {
		jsonConfig.registerJsonValueProcessor(Date.class , new JsonDateValueProcessor());
		jsonConfig.setJsonPropertyFilter(new PropertyFilter() {
			@Override
			public boolean apply(Object arg0, String name, Object arg2) {
				if (name.equals("items") || name.equals("members")
						|| name.equals("jsonConfig")) {
					return true;
				}
				return false;
			}
		});
	}
	
	@Override
	public String toString() {
		return JSONObject.fromObject(this, jsonConfig).toString();
	}
	
	

}
